<template>
	<view class="content">
		<view class="conBox">
			<view class="inps">
				<view class="key">订单号</view>
				<view class="value">
					<input type="text" v-model="dataInfo.task_no" disabled class="inp" placeholder="输入订单号"/>
				</view>
			</view>
			<view class="inps">
				<view class="key">工单标题</view>
				<view class="value">
					<input type="text" v-model="dataInfo.issue" class="inp" placeholder="输入工单标题"/>
				</view>
			</view>
			<view class="inps">
				<view class="key">工单类型</view>
				<view class="value">
					<view v-if="dataInfo.type==1">催取件</view>
					<view v-if="dataInfo.type==2">重量异常</view>
					<view v-if="dataInfo.type==3">虚假取件</view>
					<view v-if="dataInfo.type==7">签收未收到货</view>
					<view v-if="dataInfo.type==8">错件</view>
					<view v-if="dataInfo.type==9">催物流</view>
					<view v-if="dataInfo.type==10">催派送</view>
					<view v-if="dataInfo.type==13">核实退回原因</view>
					<view v-if="dataInfo.type==14">物流停滞</view>
					<view v-if="dataInfo.type==15">重新分配快递员</view>
					<view v-if="dataInfo.type==16">取消运单</view>
				</view>
			</view>
			<view class="inpss">
				<view class="key">工单内容</view>
				<view class="value" v-for="(item,index) in dataInfo.logs">
					<view class="time">{{item.created_at}}</view>
					<view class="name"><text style="color: #000;font-weight: 600;margin-right: 10rpx;">{{item.from=='user'?'我:':'客服:'}}</text>{{item.content}}</view>
					<view style="margin-top:10rpx;" v-if="item.urls.length!=0">
						<u-image width="80rpx" height="80rpx" :src="item.urls[0]" @click="preview(item.urls)"></u-image>
					</view>
				</view>
			</view>
		</view>
		
		<view class="btn" @click="show=true">回复</view>
		
		<u-popup v-model="show" mode="bottom" border-radius="20" closeable>
			<view class="replyBox">
				<view class="inpsss">
					<view class="key">回复内容</view>
					<view class="value">
						<textarea name="" id="" v-model="form.content" cols="30" rows="10" class="inp" placeholder="请填写工单内容" maxlength="-1"></textarea>
					</view>
				</view>
				<view class="inpsss">
					<view class="key">图片 <text style="margin-left: 20rpx;font-size: 20rpx;color: #999999;">* 最多上传5张</text></view>
					<view class="value">
						<u-upload :action="action" :file-list="fileList" max-count="5" :header="header" @on-success="success"></u-upload>
					</view>
				</view>
				<view class="btn" @click="reply">回复</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { workOrderInfo,workOrderAnswer } from '../../common/api.js'
	import request from '../../common/common.js'
	export default {
		data() {
			return {
				dataInfo:{},
				show:false,
				
				form:{
					work_order_id:'',
					content:'',
					urls:[]
				},
				action:request.imgUrl+'/api/wechat/file/upload',
				fileList: [],
				header:{
					authorization:'Bearer '+uni.getStorageSync("token")
				},
			}
		},
		onLoad(e) {
			this.getInfo(e.id)
		},
		methods: {
			reply(){
				console.log(this.form)
				this.form.work_order_id = this.dataInfo.id
				workOrderAnswer(this.form).then(res=>{
					if(res.code==10000){
						uni.showToast({
							title: '提交成功',
							duration: 2000,
							icon:"none"
						});
						setTimeout(()=>{
							this.getInfo(this.form.work_order_id)
							
						},500)
					}
				})
			},
			getInfo(id){
				workOrderInfo({id}).then(res=>{
					console.log(res)
					if(res.code==10000){
						this.dataInfo = res.data
					}
				})
			},
			preview(url){
				uni.previewImage({
					urls: url,
				});
			},
			success(data, index, lists, name){
				console.log(data, index, lists, name)
				if(data.code==10000){
					// let obj = {
					// 	url:data.data.url
					// }
					// this.fileList.push(obj)
					console.log(this.fileList)
					this.form.urls.push(data.data.url)
					
				}
			}
		}
	}
</script>
<style>
	page{
		background: #EDEFF2;
	}
</style>
<style scoped lang="scss">
.content{
	width: 750rpx;
	padding: 32rpx;
	box-sizing: border-box;
	.replyBox{
		padding: 12rpx;
		box-sizing: border-box;
		background: #FFFFFF;
		.inpsss{
			width: 100%;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 0 40rpx 20rpx 40rpx;
			margin-bottom: 24rpx;
			.key{
				
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
				line-height: 80rpx;
				text-align: left;
				font-style: normal;
			}
			.value{
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				.inp{
					// text-align: right;
					font-size: 28rpx;
				}
			}
		}
	}
	.btn{
		width: 100%;
		height: 88rpx;
		background: #1AA261;
		border-radius: 44rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		font-style: normal;
		margin-top: 60rpx;
	}
	.conBox{
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 20rpx 0;
		.inpss{
			width: 100%;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 0 40rpx 20rpx 40rpx;
			margin-bottom: 24rpx;
			.key{
				
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
				line-height: 80rpx;
				text-align: left;
				font-style: normal;
			}
			.value{
				margin-left: 20rpx;
				.time{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 24rpx;
					text-align: center;
					font-style: normal;
				}
				.name{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #666666;
					line-height: 28rpx;
					text-align: left;
					font-style: normal;
					margin-top: 10rpx;
				}
			}
		}
		.inps{
			width: 100%;
			height: 80rpx;
			padding: 0 40rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 1rpx solid #EEEEEE;
			.key{
				
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
				line-height: 80rpx;
				text-align: left;
				font-style: normal;
			}
			.value{
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				.inp{
					height: 80rpx;
					text-align: right;
					font-size: 28rpx;
				}
			}
		}
	}
}
</style>
